package com.helloniu.data.wb.info {

import com.helloniu.fl.util.*;

public class WhiteBoardInfo {
	public var pages:Array = new Array();//WhiteBoardPageInfo
    public var currPage:int = 0; // 0,1,2,3...

    public function WhiteBoardInfo() {
        pages = new Array();
        // 默认11页
        createPage(10);
    }

	// 创建新页面
    public function createPage(idx:Number = NaN):void {   	
    	if(isNaN(idx)) {
    		idx = pages.length;
    	}

    	if(idx < pages.length) {
    		return;
    	}

    	var startIdx:int = pages.length;
    	var pagesNum:int = idx + 1;

    	for(var i:int = startIdx; i < pagesNum; i++) {
    		var pageInfo:WhiteBoardPageInfo = new WhiteBoardPageInfo();
    		pageInfo.pageNum = i;
    		pages.push(pageInfo);
    	}

    	currPage = pages.length - 1;
    }

    public function getCurrPage():WhiteBoardPageInfo {
        return pages[currPage] as WhiteBoardPageInfo;
    }

    public function getPage(pageNum:int):WhiteBoardPageInfo {
        return pages[pageNum] as WhiteBoardPageInfo;
    }
    
    public function getPageLength():Number {
        return pages.length;
    }

	/// 删除页
    public function removePage(idx:Number = NaN):void {
    	pages.splice(idx, 1);
    }

	// 翻页
    public function gotoPage(idx:Number = NaN):void {
    	if(isNaN(idx)) {
    		// @temp tonyy
    	}

    	currPage = idx;
    }

	// 清空页面
    public function clearPage(idx:Number = NaN):void {
    	getPage(idx).removeAll();
    }

    public function generateID():String {
    	return getCurrPage().generateID();
    }
    
    public function getCurrPageNumber():Number {
    	return currPage;
    }
    
    public function toString():String {
    	var str:String = "";
    	
    	for(var i:int = 0; i < pages.length; i++) {
    		var pageInfo:WhiteBoardPageInfo = pages[i] as WhiteBoardPageInfo;
    		str = str + pageInfo.toString();
    	}
    	
    	return str; 
    }
}
}